#!/bin/bash

# ====================================================================
# 多游戏类型快速测试脚本 V4.5
# 用途：快速验证德州扑克、短牌德州、奥马哈三种游戏类型
# ====================================================================

cd "$(dirname "$0")/.."

# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'

echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "  ${CYAN}多游戏类型快速测试 V4.5${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

# 检查服务是否运行
echo "${YELLOW}正在检查服务状态...${NC}"
if ! nc -z 127.0.0.1 8889 2>/dev/null; then
    echo "${RED}❌ 服务未运行！${NC}"
    echo ""
    echo "${YELLOW}请先启动服务:${NC}"
    echo "  cd pokermind-serv-dse-tcp"
    echo "  ./server_run.sh"
    echo ""
    exit 1
fi
echo "${GREEN}✓ 服务运行中${NC}"
echo ""

# 定义测试场景
SCENARIOS=(
    "holdem_basic:${BLUE}德州扑克基础场景${NC}"
    "shortdeck_basic:${RED}短牌德州基础场景${NC}"
    "omaha_basic:${GREEN}奥马哈基础场景${NC}"
    "multi_game_comparison:${CYAN}多游戏类型对比${NC}"
)

echo "${CYAN}将依次运行以下测试场景:${NC}"
for scenario in "${SCENARIOS[@]}"; do
    IFS=':' read -r scenario_id scenario_desc <<< "$scenario"
    echo "  • $scenario_desc ($scenario_id)"
done
echo ""

# 提示用户
read -p "${YELLOW}按 Enter 开始测试，或按 Ctrl+C 取消...${NC}" -r
echo ""

# 执行测试
TOTAL_TESTS=${#SCENARIOS[@]}
PASSED_TESTS=0
FAILED_TESTS=0

for i in "${!SCENARIOS[@]}"; do
    scenario="${SCENARIOS[$i]}"
    IFS=':' read -r scenario_id scenario_desc <<< "$scenario"
    
    current=$((i + 1))
    echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
    echo "  ${CYAN}测试进度: [$current/$TOTAL_TESTS] $scenario_desc${NC}"
    echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
    echo ""
    
    # 运行测试
    ./pokermind-serv-dse-tcp/startPresetClientDev.sh "$scenario_id"
    
    if [ $? -eq 0 ]; then
        echo "${GREEN}✅ $scenario_desc - 测试通过${NC}"
        PASSED_TESTS=$((PASSED_TESTS + 1))
    else
        echo "${RED}❌ $scenario_desc - 测试失败${NC}"
        FAILED_TESTS=$((FAILED_TESTS + 1))
    fi
    
    echo ""
    
    # 如果不是最后一个测试，暂停一下
    if [ $current -lt $TOTAL_TESTS ]; then
        echo "${YELLOW}等待 2 秒后继续下一个测试...${NC}"
        sleep 2
        echo ""
    fi
done

# 测试总结
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "  ${CYAN}多游戏类型测试总结${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "${CYAN}总测试数:${NC} $TOTAL_TESTS"
echo "${GREEN}成功测试:${NC} $PASSED_TESTS"
echo "${RED}失败测试:${NC} $FAILED_TESTS"
echo ""

if [ $FAILED_TESTS -eq 0 ]; then
    echo "${GREEN}🎉 所有多游戏类型测试全部通过！${NC}"
    echo ""
    echo "${YELLOW}多游戏类型功能验证完成：${NC}"
    echo "  ✅ 德州扑克 (holdem) - 2张底牌，52张牌组"
    echo "  ✅ 短牌德州 (shortdeck) - 2张底牌，36张牌组(6-A)"  
    echo "  ✅ 奥马哈 (omaha) - 4张底牌，必须用2张底牌+3张公牌"
    echo "  ✅ 多游戏类型对比 - AI能正确识别不同游戏类型"
    EXIT_CODE=0
else
    echo "${RED}❌ 部分测试未通过，请检查失败的测试场景${NC}"
    EXIT_CODE=1
fi

echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

exit $EXIT_CODE

# ====================================================================
# 多游戏类型快速测试脚本 V4.5
# 用途：快速验证德州扑克、短牌德州、奥马哈三种游戏类型
# ====================================================================

cd "$(dirname "$0")/.."

# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'

echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "  ${CYAN}多游戏类型快速测试 V4.5${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

# 检查服务是否运行
echo "${YELLOW}正在检查服务状态...${NC}"
if ! nc -z 127.0.0.1 8889 2>/dev/null; then
    echo "${RED}❌ 服务未运行！${NC}"
    echo ""
    echo "${YELLOW}请先启动服务:${NC}"
    echo "  cd pokermind-serv-dse-tcp"
    echo "  ./server_run.sh"
    echo ""
    exit 1
fi
echo "${GREEN}✓ 服务运行中${NC}"
echo ""

# 定义测试场景
SCENARIOS=(
    "holdem_basic:${BLUE}德州扑克基础场景${NC}"
    "shortdeck_basic:${RED}短牌德州基础场景${NC}"
    "omaha_basic:${GREEN}奥马哈基础场景${NC}"
    "multi_game_comparison:${CYAN}多游戏类型对比${NC}"
)

echo "${CYAN}将依次运行以下测试场景:${NC}"
for scenario in "${SCENARIOS[@]}"; do
    IFS=':' read -r scenario_id scenario_desc <<< "$scenario"
    echo "  • $scenario_desc ($scenario_id)"
done
echo ""

# 提示用户
read -p "${YELLOW}按 Enter 开始测试，或按 Ctrl+C 取消...${NC}" -r
echo ""

# 执行测试
TOTAL_TESTS=${#SCENARIOS[@]}
PASSED_TESTS=0
FAILED_TESTS=0

for i in "${!SCENARIOS[@]}"; do
    scenario="${SCENARIOS[$i]}"
    IFS=':' read -r scenario_id scenario_desc <<< "$scenario"
    
    current=$((i + 1))
    echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
    echo "  ${CYAN}测试进度: [$current/$TOTAL_TESTS] $scenario_desc${NC}"
    echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
    echo ""
    
    # 运行测试
    ./pokermind-serv-dse-tcp/startPresetClientDev.sh "$scenario_id"
    
    if [ $? -eq 0 ]; then
        echo "${GREEN}✅ $scenario_desc - 测试通过${NC}"
        PASSED_TESTS=$((PASSED_TESTS + 1))
    else
        echo "${RED}❌ $scenario_desc - 测试失败${NC}"
        FAILED_TESTS=$((FAILED_TESTS + 1))
    fi
    
    echo ""
    
    # 如果不是最后一个测试，暂停一下
    if [ $current -lt $TOTAL_TESTS ]; then
        echo "${YELLOW}等待 2 秒后继续下一个测试...${NC}"
        sleep 2
        echo ""
    fi
done

# 测试总结
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "  ${CYAN}多游戏类型测试总结${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "${CYAN}总测试数:${NC} $TOTAL_TESTS"
echo "${GREEN}成功测试:${NC} $PASSED_TESTS"
echo "${RED}失败测试:${NC} $FAILED_TESTS"
echo ""

if [ $FAILED_TESTS -eq 0 ]; then
    echo "${GREEN}🎉 所有多游戏类型测试全部通过！${NC}"
    echo ""
    echo "${YELLOW}多游戏类型功能验证完成：${NC}"
    echo "  ✅ 德州扑克 (holdem) - 2张底牌，52张牌组"
    echo "  ✅ 短牌德州 (shortdeck) - 2张底牌，36张牌组(6-A)"  
    echo "  ✅ 奥马哈 (omaha) - 4张底牌，必须用2张底牌+3张公牌"
    echo "  ✅ 多游戏类型对比 - AI能正确识别不同游戏类型"
    EXIT_CODE=0
else
    echo "${RED}❌ 部分测试未通过，请检查失败的测试场景${NC}"
    EXIT_CODE=1
fi

echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

exit $EXIT_CODE
